London | 26-SDC-Mar | Beko | Sprint 1 | Individual shell tools exercises#352
London | 26-SDC-Mar | Beko | Sprint 1 | Individual shell tools exercises#352Abubakar-Meigag wants to merge 2 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
SlideGauge
left a comment
There was a problem hiding this comment.
There a couple of files which do not have empty line in the end of the file (like wc/script-02.sh). Could you add them please
|
|
||
| set -euo pipefail | ||
|
|
||
| awk '{print NF}' scores-table.txt |
There was a problem hiding this comment.
What does NF mean in this context and what will this line output?
There was a problem hiding this comment.
NF counts the number of fields in each row, so it was outputting the word count per line rather than the names
I've updated the command to use $1 instead, which prints the value of the first field.
|
|
||
| set -euo pipefail | ||
|
|
||
| awk '/London/ {print $1, $4}' scores-table.txt |
There was a problem hiding this comment.
What happens when we meet lines with different number of scores?
There was a problem hiding this comment.
$4 is hardcoded so it won't work for players with different number of scores
i should use $NF instead which always points to the last field.
| set -euo pipefail | ||
|
|
||
|
|
||
| grep -v "Hello" dialogue.txt |
There was a problem hiding this comment.
Will it find lines like "hello" (lowercase)?
There was a problem hiding this comment.
No, it won't catch lowercase 'hello' because grep is case-sensitive by default.
i've added the -i flag to make it case-insensitive
| # TODO: Write a command to list the files and folders in this directory. | ||
| # The output should be a list of names including child-directory, script-01.sh, script-02.sh, and more. | ||
|
|
||
| ls ../ls |
There was a problem hiding this comment.
README file says
"You should write all of your scripts assuming they're running inside the directory they're saved in."
Whilst this line works, it does redundant operation with the path, could you simplify it?
There was a problem hiding this comment.
Since the script runs in its own directory
i can just use ls with no path.
updated
| # TODO: Write a command which lists all of the files in the directory named child-directory. | ||
| # The output should be a list of names: helper-1.txt, helper-2.txt, helper-3.txt. | ||
|
|
||
| ls ../ls/child-directory No newline at end of file |
There was a problem hiding this comment.
README file says
"You should write all of your scripts assuming they're running inside the directory they're saved in."
Whilst this line works, it does redundant operation with the path, could you simplify it?
|
|
||
| echo "First exercise (sorted newest to oldest):" | ||
|
|
||
| ls -t ../ls/child-directory |
There was a problem hiding this comment.
README file says
"You should write all of your scripts assuming they're running inside the directory they're saved in."
Whilst this line works, it does redundant operation with the path, could you simplify it?
| # The output should be a list of names including: child-directory, script-01.sh, helper-1.txt (and more). | ||
| # The formatting of the output doesn't matter. | ||
|
|
||
| ls ../ls ../ls/child-directory No newline at end of file |
There was a problem hiding this comment.
Also, will it output directories contents recursively?
|
|
||
| set -euo pipefail | ||
|
|
||
| grep -l "Doctor:" *.txt |
There was a problem hiding this comment.
Will it output only lines of the Doctor or can it potentially output lines which contain "Doctor:" somewhere in the middle?
There was a problem hiding this comment.
It can match 'Doctor:' anywhere in the line
so I've added ^ to anchor it to the start.
|
|
||
| set -euo pipefail | ||
|
|
||
| awk '/London/ {print $1, $4}' scores-table.txt |
There was a problem hiding this comment.
What will happen if some of the player's have name "London" but the city is not London?
|
|
||
| set -euo pipefail | ||
|
|
||
| awk '{for (i=3; i<=NF; i++) sum[$1] += $i} END {for (name in sum) print name, sum[name]}' scores-table.txt |
There was a problem hiding this comment.
Does for (name in sum) guarantee the order of traversal?
There was a problem hiding this comment.
actually no, for (name in sum) doesn't guarantee order
because awk arrays are associative so traversal is arbitrary
i've fixed it by tracking the names in a separate ordered array
|
Wrote my notes, could you fulfil them please? |
|
Hi @SlideGauge thanks for the review, I've completed all the changes for the code review and feedback Thanks! |
Self checklist
Changelist
complete individual shell tools exercises
Questions
no questions, thanks!